﻿/**
 * Copyright (c) 2009, Carlos Mirabella
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the Carlos Mirabella nor the names of its contributors
 * may be used to endorse or promote products derived from this software without
 * specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 **/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DineroMail
{
    public class Boton
    {
        private MonedaEnum moneda;
        private bool acceptMessage = true;
        private bool acceptAddress = false;
        private String itemName;
        private float itemPrice;
        private int itemId;
        private String imageUrl;
        private String succesUrl;
        private String failUrl;
        private int transactionId;

        private String userName;
        private String userLastName;
        private String userPhone;
        private String userEmail;

        public enum MonedaEnum
        {
            Peso = 1,
            Dolar = 2
        }

        public Boton()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private String GenerateInput(String Name, String Value)
        {
            return "<input type=\"hidden\" name=\"" + Name + "\" value=\"" + Value + "\">";
        }

        public String GenerateButton()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GenerateInput("NombreItem", this.ItemName));
            sb.Append(GenerateInput("TipoMoneda", this.Moneda.ToString()));

            // Asegurarse que el precio del item lo convierta a un String del formato
            // xx.xx debido a que no acepta un precio con ,
            sb.Append(GenerateInput("PrecioItem", this.ItemPrice.ToString()));
            sb.Append(GenerateInput("E_Comercio", Properties.Settings.Default.ComercioID));
            sb.Append(GenerateInput("NroItem", this.ItemId.ToString()));
            sb.Append(GenerateInput("image_url", this.ImageUrl));
            sb.Append(GenerateInput("DireccionExito", this.SuccesUrl));
            sb.Append(GenerateInput("DireccionFracaso", this.FailUrl));
            sb.Append(GenerateInput("DireccionEnvio", Convert.ToInt32(this.acceptAddress).ToString()));
            sb.Append(GenerateInput("Mensaje", Convert.ToInt32(this.acceptMessage).ToString()));
            sb.Append(GenerateInput("trx_id", this.TransactionId.ToString()));
            
            if (this.UserName != null)
            {
                sb.Append(GenerateInput("usr_nombre", this.UserName));
                sb.Append(GenerateInput("usr_apellido", this.UserLastName));
                sb.Append(GenerateInput("usr_tel_numero", this.UserPhone));
                sb.Append(GenerateInput("usr_email", this.UserEmail));
            }
            return sb.ToString();
        }

        public String ItemName
        {
            get { return itemName.Replace(" ", "+"); }
            set { itemName = value; }
        }
        public float ItemPrice
        {
            get { return itemPrice; }
            set { itemPrice = value; }
        }

        public int ItemId
        {
            get { return itemId; }
            set { itemId = value; }
        }
        public String ImageUrl
        {
            get { return imageUrl; }
            set { imageUrl = value; }
        }

        public String SuccesUrl
        {
            get { return succesUrl; }
            set { succesUrl = value; }
        }
        public String FailUrl
        {
            get { return failUrl; }
            set { failUrl = value; }
        }

        public int TransactionId
        {
            get { return transactionId; }
            set { transactionId = value; }
        }
        public MonedaEnum Moneda
        {
            get { return moneda; }
            set { moneda = value; }
        }

        public String UserName
        {
            get { return userName; }
            set { userName = value; }
        }
        public String UserLastName
        {
            get { return UserLastName; }
            set { userLastName = value; }
        }

        public String UserPhone
        {
            get { return userPhone; }
            set { userPhone = value; }
        }
        public String UserEmail
        {
            get { return userEmail; }
            set { userEmail = value; }
        }
    }
}
